package com.iqiyi.pps.epg.core.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;

public class DateUtils {
    private static final Logger log = LoggerFactory.getLogger(DateUtils.class);

    private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public static String defDateFormat(Date date) {
        return sdf.format(date);
    }

    public static String humanTimeFromSeconds(int seconds) {
        if (seconds < 60) {
            return seconds + "秒";
        }

        Map<Integer, String> defaults = new LinkedHashMap<Integer, String>(){{
            put(604800, "周");
            put(86400, "天");
            put(3600, "时");
            put(60, "分");
            put(1, "秒");
        }};

        int temp;
        StringBuilder sb = new StringBuilder();
        for (Map.Entry<Integer, String> item : defaults.entrySet()) {
            if (seconds > item.getKey()) {
                temp = seconds / item.getKey();
                sb.append(temp);
                sb.append(item.getValue());
                seconds -= temp * item.getKey();
            }
        }
        return sb.toString();
    }
}
